package com.ruoyi.web.controller.crm;

import com.bonuo.crm.domain.Province;
import com.bonuo.crm.service.ProvinceService;
import com.bonuo.crm.service.WarZoneService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/crm/province")
@Api(tags = "省份分配")
public class ProvinceController extends BaseController {
    @Autowired
    private ProvinceService provinceService;

    //查询省份分配列表
    @GetMapping("/list")
    @ApiOperation(value = "查询省份列表",httpMethod = "GET")
    public TableDataInfo list(Province province,Integer pageNum,Integer pageSize){
        if(pageNum != null && pageSize != null){
            startPage();
        }
        List<Province> list = provinceService.selectProvinceList(province);
        return getDataTable(list);
    }

    //添加省份分配
    @PostMapping("/add")
    @ApiOperation(value = "添加省份",httpMethod = "POST")
    public AjaxResult add(@RequestBody Province province){
        Integer add = provinceService.add(province);
        return toAjax(add);
    }
    //修改省份分配

    @PutMapping("/update")
    @ApiOperation(value = "修改省份",httpMethod = "PUT")
    public AjaxResult update(@RequestBody Province province){
        Integer update = provinceService.update(province);
        return toAjax(update);
    }

    //删除省份分配
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除省份",httpMethod = "DELETE")
    public AjaxResult delete(@PathVariable Integer id){
        Integer delete = provinceService.delete(id);
        return toAjax(delete);
    }

    //导出省份分配
    @PostMapping("/export")
    @ApiOperation(value = "导出省份",httpMethod = "POST")
    public void export(HttpServletResponse response, Province province){
        List<Province> list = provinceService.selectProvinceList(province);
        ExcelUtil<Province> util = new ExcelUtil<Province>(Province.class);
        util.exportExcel(response, list, "省份数据");
    }
}
